package com.tywj.lib.social.share

import android.app.Activity
import android.os.Bundle
import com.tywj.lib.social.SocialUtil
import com.alipay.share.sdk.openapi.BaseReq
import com.alipay.share.sdk.openapi.BaseResp
import com.alipay.share.sdk.openapi.IAPAPIEventHandler

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/16
 *     desc   : 支付宝分享结果处理Activity
 *     version: 1.0.0
 * </pre>
 */
open class AlipayShareHandlerActivity : Activity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        SocialUtil.alipayApi.handleIntent(intent, object : IAPAPIEventHandler {

            override fun onReq(req: BaseReq) {}

            override fun onResp(resp: BaseResp) {
                if (resp.errCode == BaseResp.ErrCode.ERR_OK) {
                    SocialUtil.share.callback?.onSuccess()
                } else {
                    SocialUtil.share.callback?.onError()
                }
                SocialUtil.share.callback = null

                finish()
            }
        })
    }
}